<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 农家乐
 * Created by PhpStorm.
 * User: 66diqiu-li
 * Date: 14-8-22
 * Time: 上午10:54
 */
class Test_Index_module extends CI_Module
{


    public function __construct(){
        parent::__construct();
        $this->sid = $GLOBALS['sid'];
        $this->data = $GLOBALS['config'];


        $this->load->model('order.Orderlog_model');
        $this->load->model('order.Orderpaylog_model');
        $this->load->model('order.Ordercontacts_model');
        $this->load->model('order.Orderinfo_model');
        $this->load->model('order.Orderhotel_model');
        $this->load->model('order.Orderroom_model');
        $this->load->model('hotel.Hotel_model');
        $this->load->model('order.Ordertourist_model');
        $this->load->model('order.Orderhotelgoods_model');
        $this->load->model('member.User_model');
    }

    public function tsms()
    {
//        $mobile = '15295535303';
        $mobile = '15295535303';
        $content = array();
        $res = $this->User_model->_send_sms($mobile,'SMS_10885119',$content);
        print_r($res);
    }

    public function tr()
    {
      $res = $this->Orderroom_model->get_conflict_rooms('186',array(32,33),'2016-06-27','2016-07-30');


        $new = array();
        $return = array();

        if($res)
        {
            foreach ($res as $index=>$item)
            {
                $t = array();
                if(is_array($item)&&!empty($item))
                {
                    foreach ($item as $key => $value)
                    {
                        $t[$value['room_id']][$value['order_id']][] = $value ;
                    }
                }
                $new[] = $t ;
            }
        }

        if($new)
        {
            foreach ($new as $index => $item)
            {
               $keys = array_keys($item);
               $values = array_values($item);
               $return[$keys[0]] = $values[0];
            }
        }

        print_r($return);
      /* if($res)
       {
           foreach ($res as $index=>$item)
           {
               $tmp = array();
               $simple = array();
               $exclude = array();
               if(is_array($item)&&!empty($item))
               {
                   foreach ($item as $key => $value)
                   {
                       if ($value['order_id'] == $item[$key + 1]['order_id'] || (!isset($item[$key + 1]) && $value['order_id'] == $item[$key - 1]['order_id'])) //从第一个开始 当前值 与下一个值相同  或者 最后一个值与上一个相同
                       {
                           $simple[] = $value;
                           $tmp[] = $simple;
                       }
                       else
                       {
                           $exclude[] = $value;
                           $tmp[] = $exclude;
                       }

                   }
               }

               $new[$index]= $tmp;
           }
       }*/

//     print_r($new);

    }
    public function check_room_book_state($order_id,$room_ids = array(),$start_date ,$end_date)
    {

        $where = array();

        foreach ($room_ids as $index => $room_id)
        {
            $where[$index]  = " order_id != $order_id and room_id = $room_id and date between '$start_date' and '$end_date' "  ;
        }

        if($where){
            foreach ($where as $index => $item)
            {
                $res[] = $this->Orderroom_model->get_room_array($item);
            }
        }

        return $res;

    }

    public function record()
    {

        die('');
    }
}